home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-03
/
iqb9109.zip
/
CVTREAL.BAS
< prev
next >
Wrap
BASIC Source File
|
1991-09-09
|
3KB
|
124 lines
' CvtReal.Bas
' Program to convert IEEE floating point numbers to MBF and backwards again
'
CONST FALSE = 0, TRUE = NOT FALSE
TYPE SingleMBFStr
Bytes AS STRING * 4
END TYPE
TYPE TrickSingle
Bytes AS SINGLE
END TYPE
TYPE DoubleMBFStr
Bytes AS STRING * 8
END TYPE
TYPE TrickDouble
Bytes AS DOUBLE
END TYPE
DECLARE FUNCTION LZPadStr$ (N$, pLen%)
DECLARE SUB ShowSingle (A AS ANY)
DECLARE SUB ShowDouble (A AS ANY)
DIM singleCvBuf AS SingleMBFStr
DIM ieeeSingle AS TrickSingle
DIM mbfSingle AS TrickSingle
DIM doubleCvBuf AS DoubleMBFStr
DIM ieeeDouble AS TrickDouble
DIM mbfDouble AS TrickDouble
DIM Results(20)
' Begin main program
ON KEY(1) GOSUB FKey1Handler: KEY(1) ON
ON KEY(2) GOSUB FKey2Handler: KEY(2) ON
ON KEY(3) GOSUB FKey3Handler: KEY(3) ON
PRINT "Press F1 to convert a single-precision number,"
PRINT "Press F2 to convert a double-precision number, or"
PRINT "Press F3 to quit."
PRINT
Done% = FALSE
DO UNTIL Done%
' Everything's done in the handlers
' This is the future for BASIC main programs!
LOOP
END
' This is the function key handler for converting
' single-precision real numbers
FKey1Handler:
INPUT "Enter a single-precision floating point number: ", _
ieeeSingle.Bytes
singleCvBuf.Bytes = MKSMBF$(ieeeSingle.Bytes)
LSET mbfSingle = singleCvBuf
PRINT
PRINT "The number you typed in IEEE format is ";
CALL ShowSingle(ieeeSingle)
PRINT "The number you typed in MBF format is ";
CALL ShowSingle(mbfSingle)
X! = mbfSingle.Bytes
RETURN
' This is the function key handler for converting
' double-precision real numbers
FKey2Handler:
INPUT "Enter a double-precision floating point number: ", _
ieeeDouble.Bytes
doubleCvBuf.Bytes = MKDMBF$(ieeeDouble.Bytes)
LSET mbfDouble = doubleCvBuf
PRINT
PRINT "The number you typed in IEEE format is ";
CALL ShowDouble(ieeeDouble)
PRINT "The number you typed in MBF format is ";
CALL ShowDouble(mbfDouble)
X# = mbfDouble.Bytes
PRINT "And check this out: "; ieeeDouble.Bytes, X#
RETURN
' This is the function key handler to exit the program
FKey3Handler:
Done% = TRUE
RETURN
FUNCTION LZPadStr$ (N$, pLen%) STATIC
' Function to pad a string variable
' on the left with zeroes and return it as a string.
LZPadStr$ = STRING$(pLen% - LEN(N$), "0") + N$
END FUNCTION
SUB ShowSingle (A AS TrickSingle) STATIC
' Subprogram to display a single-precision floating-point
' number in hexadecimal notation
X = VARPTR(A)
FOR Byte% = 3 TO 0 STEP -1
PRINT LZPadStr$(HEX$(PEEK(X + Byte%)), 2);
NEXT Byte%
PRINT
END SUB
SUB ShowDouble (A AS TrickDouble) STATIC
' Subprogram to display a double-precision floating-point
' number in hexadecimal notation
X = VARPTR(A)
FOR Byte% = 7 TO 0 STEP -1
PRINT LZPadStr$(HEX$(PEEK(X + Byte%)), 2);
NEXT Byte%
PRINT
END SUB